package com.xhga.register;

import org.I0Itec.zkclient.ZkClient;

/**
 * Created by Hua wb on 2018/11/29.
 */
public class RpcRegister {

    public void createNode(String serverAddress){
        ZkClient zkClient = new ZkClient(ZkConfig.LOCALHOST, ZkConfig.SESSION_TIMEOUT);
        if (zkClient != null) {
            try {
                boolean exists = zkClient.exists(ZkConfig.PATH);
                if (! exists) {
                    zkClient.createPersistent(ZkConfig.PATH);
                }
                boolean node = zkClient.exists(ZkConfig.NODE);
                if (! node) {
                    zkClient.createEphemeral(ZkConfig.NODE, serverAddress);
                }
            } catch (Exception e) {
                System.out.println("register:创建节点失败.");
            }
        }
    }
}
